package com.example.park2212.devices

import androidx.lifecycle.MutableLiveData
import com.example.lib_base.entity.DevicesBean
import com.example.lib_base.entity.DevicesBeanItem
import com.example.lib_base.mvvm.BaseViewModel
import com.example.lib_base.net.ApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class DevicesVewModel@Inject constructor(val apiservice: ApiService) :BaseViewModel() {

    val getDevicesSuccess = MutableLiveData<DevicesBean>()
    fun getDevices(){
       httpRequest({
           apiservice.getDevices()
       },getDevicesSuccess::postValue)
    }

    val addDevicesSuccess = MutableLiveData<DevicesBeanItem>()
    fun addDevices(item: DevicesBeanItem){
        httpRequest({
            apiservice.addDevices(mapToBody(item))
        },addDevicesSuccess::postValue)
    }

    val devicesSearchSuccess = MutableLiveData<DevicesBean>()
    fun devicesSearch(keyword:String){
        httpRequest({
            apiservice.devicesSearch(keyword)
        },devicesSearchSuccess::postValue)
    }
}